package enum05;

import org.junit.Test;

import java.lang.reflect.Method;

/**
 *
 * Java中所有用enum定义的枚举默认会继承一个类:java.lang.Enum
 * Class类中的方法:
 *   Class<? super T> getSuperclass()
 *          获取该字节对象的父字节码对象
 *    Method[] getMethods()
 *         获取该字节码对象中所有public修饰的成员方法
 *
 * 枚举中的常用方法:
 *   public static Week[] values()
 *      获取所有的枚举常量,并把所有的枚举常量封装到一个数组返回
 *   public static Week valueOf(String str)
 *   public final String name()返回此枚举常量的名称，在其枚举声明中对其进行声明
 */
public class WeekDemo {
	@Test
	public void testMethod01() {
		System.out.println(Week.class.getSuperclass());//class java.lang.Enum
	}

	@Test
	public void testMethod02() {
       //1.利用字节码对象获取所有的成员方法
		Method[] methods = Week.class.getMethods();

		//2.遍历methods数组
		for (Method method : methods) {
			System.out.println(method);
		}
	}

	@Test
	public void testMethod03() {
		Week[] weeks = Week.values();
		for (Week week : weeks) {
			System.out.println(week);
		}
	}

	@Test
	public void testMethod04() {
		System.out.println(Week.valueOf("MONDAY"));
		System.out.println(Week.valueOf("MONDAY")==Week.MONDAY);//true
	}

	@Test
	public void testMethod05() {
		System.out.println(Week.FRIDAY.name());//跟toString()原理相同
		System.out.println(Week.FRIDAY);
		System.out.println(Week.FRIDAY.toString());
	}


}
